package Server.Jsmj.RGCP.QILE;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class RGCPGroup{
	List<RGCP> list;
	
	private RGCPGroup(){
		
	}
	public RGCPGroup(RGCP majiang1, RGCP majiang2){
		list = new ArrayList<RGCP>();
		list.add(majiang1);
		list.add(majiang2);
	}
	public RGCPGroup(RGCP majiang1, RGCP majiang2, RGCP majiang3){
		list = new ArrayList<RGCP>();
		list.add(majiang1);
		list.add(majiang2);
		list.add(majiang3);
	}
	public RGCPGroup(List<RGCP> list1, List<RGCP> list2, List<RGCP> list3){
		list = new ArrayList<RGCP>();
		list.addAll(list1);
		list.addAll(list2);
		list.addAll(list3);
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null){
			return false;
		}
		if(obj instanceof RGCPGroup){
			RGCPGroup objMajiangGroup = (RGCPGroup)obj;
			if(this.list != null && objMajiangGroup.list != null && this.list.size() == objMajiangGroup.list.size()){
				this.sort();
				objMajiangGroup.sort();
				for(int i =0; i < this.list.size(); i++){
					if(this.list.get(i).getO_value() != objMajiangGroup.list.get(i).getO_value()){
						return false;
					}
				}
				return true;
			}
		}
		return false;
	}
	
	private void sort(){
		if(this.list != null && this.list.size() > 0){
			Collections.sort(this.list, new Comparator<RGCP>(){
				@Override
				public int compare(RGCP o1, RGCP o2) {
					if(o1.getO_value() > o1.getO_value()){
						return 1;
					}else if(o1.getO_value()< o2.getO_value()){
						return -1;
					}else{
						return 0;
					}
				}
			});
		}
	}
	
}
